﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BusesXml.aspx.cs" Inherits="Buses" %><?xml version="1.0"?>
<buses>
<%
    int routeNum = int.Parse(Page.Request["route"]);
    BusLib.Route route = BusLib.Route.GetRouteByNumber(routeNum);

    route.Update();
    
    foreach (BusLib.Bus bus in route.Buses)
    { %>
 <bus>
    <route><%= route.route_short_name %></route>
    <vehicle><%= bus.VehicleNum %></vehicle>
    <lat><%= bus.CurrentLatitude %></lat>
    <lng><%= bus.CurrentLongitude %></lng>
    <heading><%= bus.CurrentHeading %></heading>
    <PositionLog><%
        // All events in the last 1/2 hour:
        foreach (BusLib.Event e in bus.GetLatestEventsByTime(new TimeSpan(0,30,0)))
        {
            if (e.EventType == "Position")
            {%>
                <Position>                    
                    <lat><%= e.Latitude %></lat>
                    <lng><%= e.Longitude %></lng>                    
                </Position>
            <%}
        }
    %></PositionLog>
 </bus>
 <%} %>
</buses>
